package cn.itlaobing.web.servlet;

import cn.itlaobing.exception.MyException;
import cn.itlaobing.model.DtoTrainModel;
import cn.itlaobing.service.TrainService;
import cn.itlaobing.web.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017-11-09.
 */
@WebServlet(value = "/Query/*")
public class TrainServlet extends BaseServlet{
    @RequestMapping("/QueryByTrainnum")
    public void QueryByTrainnum(HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        request.setCharacterEncoding("utf-8");
        String trainnum=request.getParameter("trainNum");
        String station1=request.getParameter("station1");
        String station2=request.getParameter("station2");
        System.out.println(trainnum);
        System.out.println(station1);
        System.out.println(station2);
        TrainService ts=new TrainService();
        DtoTrainModel dtm=null;
        try {
            dtm=ts.QueryAll(trainnum,station1,station2);
        } catch (MyException e) {
            e.printStackTrace();
        }
        /*if(dtm==null)
        {
            try {
                response.sendRedirect("/blank.jsp");
                return;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }*/
        request.setAttribute("REQUEST_DTOMODEL", dtm);
        try {
            request.getRequestDispatcher("/WEB-INF/views/price.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
